import Vue from "vue"
import VueRouter from "vue-router"
import HomeView from "../views/HomeView.vue"

Vue.use(VueRouter)

const routes = [
  //登录页面
  {
    path: "/user/login",
    name: "login",
    component: () => import("../views/user/Login.vue"),
  },
  {
    path: "/",
    redirect: "/user/login",
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    // redirect: "../home/index",
    children: [
      // {
      //   path: "index",
      //   name: "index",
      //   component: () => import("../views/Index.vue"),
      // },
      {
        path: "individual",
        name: "individual",
        meta: {
          thumb: ["个人中心", "个人信息"],
        },
        component: () => import("../views/admin/Individual.vue"),
      },
      {
        path: "individual-update",
        name: "individual-update",
        meta: {
          thumb: ["个人中心", "修改信息"],
        },
        component: () => import("../views/admin/IndividualUpdate.vue"),
      },
      {
        path: "commodity-add",
        name: "commodity-add",
        meta: {
          thumb: ["商品管理", "添加商品"],
        },
        component: () => import("../views/commodity/commodityAdd.vue"),
      },
      {
        path: "commodity-list",
        name: "commodity-list",
        meta: {
          thumb: ["商品管理", "商品列表"],
        },
        component: () => import("../views/commodity/commodityList.vue"),
      },
      {
        path: "ordinary-list",
        name: "ordinary-list",
        meta: {
          thumb: ["用户管理", "用户列表"],
        },
        component: () => import("../views/ordinary/ordinaryList.vue"),
      },
      {
        path: "administrator-add",
        name: "administrator-add",
        meta: {
          thumb: ["管理员管理", "添加管理员"],
        },
        component: () => import("../views/administrator/administratorAdd.vue"),
      },
      {
        path: "administrator-list",
        name: "administrator-list",
        meta: {
          thumb: ["管理员管理", "管理员列表"],
        },
        component: () => import("../views/administrator/administratorList.vue"),
      },
      {
        path: "administrator-update/:id",
        name: "administrator-update",
        meta: {
          thumb: ["管理员管理", "修改管理员"],
        },
        component: () =>
          import("../views/administrator/administratorUpdate.vue"),
      },
      {
        path: "commodity-update/:id",
        name: "commodity-update",
        meta: {
          thumb: ["商品管理", "商品信息", "修改商品"],
        },
        component: () => import("../views/commodity/commodityUpdate.vue"),
      },
      {
        path: "commodity-select/:id",
        name: "commodity-select",
        meta: {
          thumb: ["商品管理", "商品信息"],
        },
        component: () => import("../views/commodity/commoditySelect.vue"),
      },
      // {
      //   path: "cinema-showingon-plan-list/:id",
      //   name: "cinema-showingon-plan-list",
      //   meta: {
      //     thumb: ["影院管理", "影院列表", "放映厅列表", "排片计划列表"],
      //   },
      //   component: () => import("../views/cinema/showingonPlanList.vue"),
      // },
      // {
      //   path: "seat-template/:roomId",
      //   name: "seat-template",
      //   meta: {
      //     thumb: ["影院管理", "影院列表", "放映厅列表", "配置座位模板"],
      //   },
      //   component: () => import("../views/cinema/CinemaRoomSeatTemplate.vue"),
      // },
    ],
  },
]

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
})
// import store from "@/store"
//添加路由守卫
router.beforeEach((to, from, next) => {
  console.log("from", from)
  console.log("to", to)
  let id = localStorage.getItem("id")
  if (to.path == "/user/login" || id) {
    next()
  } else {
    router.push("/user/login")
  }
})
export default router
